package com.dashboard.cloud.nacos.configure.service;

import com.dashboard.cloud.nacos.configure.properties.UserProperties;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Properties;

/**
 * All rights Reserved, Designed By www.super-master.com
 *
 * @ProjectName: spring-cloud-dashboard
 * @Package: com.dashboard.cloud.nacos.configure.service
 * @ClassName: NacosRefreshConfigureService
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2024/11/8 14:36
 * @Version: V1.0
 * @Copyright: 2024 www.super-master.com Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Service
//在控制器类加入@RefreshScope注解使当前类下的配置支持Nacos的动态刷新功能
@RefreshScope
public class NacosRefreshConfigureService {

    @Value("${nacos.configure.refresh.info}")
    private String configInfo;

    public Properties obtainRefreshConfigure() {
        Properties properties = new Properties();
        properties.put("refresh.info", configInfo);
        return properties;
    }

    // -----------------------------------------------------------------------------------------------------------------
    @Resource
    private UserProperties userProperties;

    public Properties obtainModuleConfigure() {
        Properties properties = new Properties();
        properties.put("userId", userProperties.getUserId());
        properties.put("userName", userProperties.getUserName());
        properties.put("email", userProperties.getEmail());
        properties.put("mobile", userProperties.getMobile());
        return properties;
    }
}